package com.base.controller;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.base.comm.CommContent;
import com.base.po.voip.SelfShopWithdrawals;
import com.base.service.LogsService;
import com.base.service.SelfShopWithdrawalsService;
import com.base.utils.IP;

@Controller
@RequestMapping("/admin")
public class update_SelfShopWithdrawals {
	@Autowired
	private LogsService logsService;// log日志
	@Autowired
	private SelfShopWithdrawalsService selfShopWithdrawalsService;
	
	String SUCCESS = "success";

	// 更改商户信息
	@RequestMapping(value = "/updateSelfShopWithdrawals", method = RequestMethod.POST)
	public void updateSelfShopWithdrawals(HttpServletRequest request, HttpServletResponse response,
			@RequestParam(value = "id", required = true) String id,  String remark, 
			Byte status) throws Exception {
		// 返回参数
		response.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=UTF-8");
//		String adminUserId = (String) request.getSession().getAttribute("adminUserId");
	
		SelfShopWithdrawals selfShopWithdrawals = selfShopWithdrawalsService.selectByPrimaryKey(id);
		PrintWriter out = response.getWriter();
		
		if (id == null) {
			out.print("浏览器在点击的过程中发现丢失了用户信息，请您刷新重试！");
			return;
		} else {
			selfShopWithdrawals.setRemark(remark);
			selfShopWithdrawals.setStatus(status);
			int code = selfShopWithdrawalsService.updateByPrimaryKeySelective(selfShopWithdrawals);
			String usernamesys = (String) request.getSession().getAttribute("useracc");
			if (code == 1) {
				logsService.insert(CommContent.TYPE_UPDATE, selfShopWithdrawals.getName() + "提现记录成功", usernamesys, true,
						IP.getIpAddr(request));
				out.print(SUCCESS);
			} else {
				logsService.insert(CommContent.TYPE_UPDATE, selfShopWithdrawals.getName() + "提现记录失败", usernamesys, true,
						IP.getIpAddr(request));
				out.print("更改失败，请您重试");
			}
		}
	}
}
